apt-get update


apt-get install conntrack
apt-get install dhcp3-server
apt-get install sudo
apt-get install squid
apt-get install apache2
apt-get install php5
apt-get install php5-cli
apt-get install php5-sqlite
apt-get install sed
apt-get install bind9
apt-get install ntpdate


# copy data
cp -R /opt/wlan/install/data /opt/wlan/data

chown -R www-data /opt/wlan
chmod -R u+rw /opt/wlan/data
chmod -R u+rwx /opt/wlan/cron/setclock.sh


cat ./interfaces > /etc/network/interfaces

# add wlan DNS zone settings
cat ./named.conf >> /etc/bind/named.conf

# copy local db-file for wlan
cp ./db.wlan /etc/bind/db.wlan

# configure apache2 to listen on port 80 AND 81
echo "Listen 81" >> /etc/apache2/ports.conf

# delete default apache site config
rm /etc/apache2/sites-enabled/*

# enable mod_rewrite
ln -s /etc/apache2/mods-available/rewrite.load /etc/apache2/mods-enabled/rewrite.load

# copy apache config
cp ./apache.conf /etc/apache2/sites-enabled/wlan

# copy firewall script
cp ./wlan_firewall /etc/init.d/wlan_firewall
chmod +x /etc/init.d/wlan_firewall
update-rc.d wlan_firewall defaults

# configure dhcp server
mv /etc/dhcp3/dhcpd.conf /etc/dhcp3/dhcpd.conf.old

sed 's/authoritative;/#authoritative;/g' /etc/dhcp3/dhcpd.conf.old > /etc/dhcp3/dhcpd.conf.temp1
sed 's/option domain-name/#option domain-name/g' /etc/dhcp3/dhcpd.conf.temp1 > /etc/dhcp3/dhcpd.conf.temp2
sed 's/option domain-name-servers/#option domain-name-servers/g' /etc/dhcp3/dhcpd.conf.temp2 > /etc/dhcp3/dhcpd.conf

rm /etc/dhcp3/dhcpd.conf.temp1
rm /etc/dhcp3/dhcpd.conf.temp2
rm /etc/dhcp3/dhcpd.conf.old

cat ./dhcpd.conf >> /etc/dhcp3/dhcpd.conf

# set chmod
chown www-data /etc/dhcp3/dhcpd.conf

# rmtrack script
cp ./rmtrack /usr/bin/rmtrack
chmod +x /usr/bin/rmtrack

# configure squid proxy server
mv /etc/squid/squid.conf /etc/squid/squid.conf.old
sed 's/http_port 3128/http_port 3128 transparent/g' /etc/squid/squid.conf.old > /etc/squid/squid.conf.temp1
sed 's/access_log\ \/var\//#access_log\ \/var\//g' /etc/squid/squid.conf.temp1 > /etc/squid/squid.conf.temp2
sed 's/http_access\ deny\ all/#http_access\ deny\ all/g' /etc/squid/squid.conf.temp2 > /etc/squid/squid.conf

rm /etc/squid/squid.conf.old
rm /etc/squid/squid.conf.temp1
rm /etc/squid/squid.conf.temp2

echo "acl our_networks src 10.0.0.0/16" >> /etc/squid/squid.conf
echo "http_access allow our_networks" >> /etc/squid/squid.conf
echo "access_log /opt/wlan/data/log squid" >> /etc/squid/squid.conf
echo "logfile_rotate 0" >> /etc/squid/squid.conf
echo "http_access deny all" >> /etc/squid/squid.conf



# install cronjobs
crontab -l > /var/wlancron
cat ./cronjobs >> /var/wlancron
crontab /var/wlancron
rm /var/wlancron



